import java.io.IOException;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;


public class SkillsBoss {
	
	public  int x, y;
	public  int w,h;
	public static int xD, yD;
	public static int wD, hD;
	public int type;	
	public int currFrame = 0;
	public int ROW = 5;
	public int direc;
	public int timeFire;
	
	public static boolean isdisappear = false;
	
	
	public static final int GAS = 0;
	public static final int STONE = 1;
	public static final int FIRE_HOLE = 3;
	public static final int FLASH = 4;
	
	public static int mstate ;
	public static int APPEAR = 0;
	public static int DISAPPEAR = 1;
	
	public static int DIREC_LEFT = 1;
	public static int DIREC_RIGHT = 2;
	
	
	public Image img;
	
	public SkillsBoss(int x1, int y1, int t, int direc1)
	{
		xD = x = x1;
		yD = y = y1;
		type = t;		
		direc = direc1;
		
		init(type);
		
		wD = w = img.getWidth();
		hD = h = img.getHeight()/ROW;
		mstate = APPEAR;
		isdisappear = false;;
	}
	
	public void init(int type1)
	{
		try {
			switch (type1) {
			case GAS:
				img = Image.createImage("/gas.png");
				break;
			case STONE:
				img = Image.createImage("/gas.png");
				break;
			case FIRE_HOLE:
				img = Image.createImage("/gas.png");
				break;
			case FLASH:
				img = Image.createImage("/gas.png");
				break;

			default:
				break;
			}						
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	

	
	public void update()
	{				
		moveSkills();		
		setRemoveBoom();

	}
	
	public void setRemoveBoom()
	{
		if(mstate == DISAPPEAR)
		{
			Cuop.vecboom.removeElement(this);
		}
	}
	
	
	int xx = 5 ;
	int yy = 5;
	public void moveSkills()
	{	
		
		switch (Level.currentLevel) {
		case 1:
			if(direc == DIREC_LEFT)
			{
				xx = -4;
			}
			else if(direc == DIREC_RIGHT )
			{
				 xx = 4;
			}

			x += xx;
			xD = x;
			yD = y;
			currFrame = ++ currFrame% ROW;
			if(xD <Cuop.cmX - w || xD + w > Cuop.cmX+ Mscreen.widthScreen )
			{
				x+=0;			
				mstate = DISAPPEAR;
				isdisappear = true;
			}				
			
			break;
			
		case 2:
			if(direc == DIREC_LEFT)
			{
				xx = -xx;
			}
			else if(direc == DIREC_RIGHT )
			{
				 xx = xx;
			}
			
			if( y >=Mscreen.heightScree )
			{
				yy = -yy;
			}

			if(y<=0)
			{
				yy = -yy;
			}

		
			x += xx;
			y += yy;
			xD = x;
			yD = y;
			currFrame = ++ currFrame% ROW;
			
			if(xD <Cuop.cmX - w || xD + w > Cuop.cmX+ Mscreen.widthScreen )
			{
						
				mstate = DISAPPEAR;
				isdisappear = true;
			}
			
			
			break;
			
		case 3:
			timeFire++;

			if(y<=0)
			{
				yy = -yy-2;
			}
			
			y += yy;
			xD = x;
			yD = y;
			currFrame = ++ currFrame% ROW;
			if( yD  >  Mscreen.heightScree )
			{
				mstate = DISAPPEAR;
				isdisappear = true;
			}
			break;
			
		case 4 :
			if(direc == DIREC_LEFT)
			{
				xx = -5;
			}
			else if(direc == DIREC_RIGHT )
			{
				 xx = 4;
			}

			x += xx;
			xD = x;
			yD = y;
			currFrame = ++ currFrame% ROW;
			if(xD <Cuop.cmX - w || xD + w > Cuop.cmX+ Mscreen.widthScreen )
			{
				x+=0;			
				mstate = DISAPPEAR;
				isdisappear = true;
			}				
			break;
			
		default:
			break;
		}
		
		

				
	}
	

	
	public void paint(Graphics g)
	{
		switch (type) {
		case GAS:
			g.drawRegion(img, 0, h*currFrame, w, h, 0, xD, yD, Graphics.VCENTER|Graphics.HCENTER);
			break;
		case STONE:
			g.drawRegion(img, 0, h*currFrame, w, h, 0, xD, yD, Graphics.VCENTER|Graphics.HCENTER);
			break;
		case FIRE_HOLE:
			g.drawRegion(img, 0, h*currFrame, w, h, 0, xD, yD, Graphics.VCENTER|Graphics.HCENTER);
			break;
		case FLASH:
			g.drawRegion(img, 0, h*currFrame, w, h, 0, xD, yD, Graphics.VCENTER|Graphics.HCENTER);
			break;

		default:
			break;
		}
		
	}
	
	
}
